package com.yw.swagger.service.serviceImpl;


import com.yw.swagger.mapper.RecordsMapper;
import com.yw.swagger.model.Utree;
import com.yw.swagger.service.RecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class RecordsServiceImpl implements RecordsService {
    @Autowired
    private RecordsMapper recordsMapper;

    //查询办公室档案
    @Override
    public List<Utree> selectFileType(String deptName) {
        Map<String,Object> map=recordsMapper.selectGDFL(deptName);
        Map<String,Object> map1=recordsMapper.selectBGS(deptName);
        List<Map<String,Object> >map2=recordsMapper.selectDA(deptName);
        List<Utree> utrees=new ArrayList<>();
        Utree utree1=new Utree();
        utree1.setId(Long.valueOf((int)map.get("Id")));
        utree1.setpId(0L);
        utree1.setName((String)map.get("Doc_Name"));
        utree1.setTitle((String)map.get("Doc_Name"));
        utrees.add(utree1);
        Utree utree2=new Utree();
        utree2.setId(Long.valueOf((int)map1.get("Id")));
        utree2.setpId(Long.valueOf((int)map.get("Id")));
        utree2.setName((String)map1.get("Doc_Name"));
        utree2.setTitle((String)map1.get("Doc_Name"));
        utrees.add(utree2);
        for(Map m:map2){
            Utree utree3=new Utree();
            utree3.setId(Long.valueOf((int)m.get("Id")));
            utree3.setpId(Long.valueOf((int)map1.get("Id")));
            utree3.setName((String)m.get("Doc_Name"));
            utree3.setTitle((String)m.get("Doc_Name"));
            utrees.add(utree3);
        }
       return utrees;
//     return getChildItem(utrees, 0L) ;
    }

    List<Utree>  getChildItem(List<Utree> list,Long prentId){
        List<Utree> temps=new ArrayList<>();
        for(Utree item:list){
            if(item.getpId().equals(prentId)){
                item.setList(getChildItem(list, item.getId()));
                temps.add(item);
            }
        }
        return  temps;
    }

}
